
package com.example;

import com.example.entity.Request;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.http.HttpStatus;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @PostMapping("/register")
    public ResponseEntity<String> register(@RequestBody Request registrationRequest)
    {
        // 实现注册逻辑，例如检查账号是否已存在，加密密码，保存到数据库等
        boolean isRegistered = registrationRequest.registerAccount(registrationRequest.getUsername(), registrationRequest.getPassword());

        if (isRegistered)
        {
            return ResponseEntity.ok("注册成功");
        }
        else
        {
            // 如果注册失败，例如账号已存在，返回相应的错误信息
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("注册失败，账号可能已存在");
        }
    }

}
